﻿@using Microsoft.AspNetCore.Components

<div class="switch @switchClassName">
    <label for="@Item">@Text</label>
    <div class="switch-bg">
        <input id="@Item" name="@Item" type="checkbox" @bind="IsChecked" disabled="@Disabled" class="switch-hidden" />
        <span class="switch-handle"></span>
    </div>
</div>

@code {
    [Parameter] public string Item { get; set; }
    [Parameter] public string Text { get; set; }
    [Parameter] public bool Disabled { get; set; } = false;
    [Parameter] public bool Checked { get; set; } = false;

    private bool isChecked;
    private string switchClassName = "switch-false";

    private bool IsChecked
    {
        get => isChecked;
        set
        {
            if (isChecked != value)
            {
                isChecked = value;
                switchClassName = isChecked ? "switch-true" : "switch-false";
            }
        }
    }

    protected override void OnParametersSet()
    {
        isChecked = Checked;
        switchClassName = isChecked ? "switch-true" : "switch-false";
    }
}
